
import static org.junit.Assert.assertEquals;

import model.Item;
import model.Order;
import model.UpdataOrder;
import model.Updatastater;
import model.enums.ItemType;
import org.junit.Test;
import service.OrderService;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class JunitDemo {

    // 主食类
    Item hamburger = new Item("H001", "汉堡", 15.0, ItemType.MAIN);
    Item fries = new Item("F002", "薯条", 15.0, ItemType.MAIN);
    Item chickenWrap = new Item("W003", "鸡肉卷", 12.0, ItemType.MAIN);

    // 饮料类
    Item icedCoffee = new Item("C004", "冰咖啡", 10.0, ItemType.DRINK);
    Item cola = new Item("C005", "可乐", 8.0, ItemType.DRINK);
    Item orangeJuice = new Item("J006", "橙汁", 9.0, ItemType.DRINK);

    // 甜品类
    Item iceCream = new Item("D007", "冰淇淋", 6.0, ItemType.DESSERT);
    Item cake = new Item("D008", "蛋糕", 12.0, ItemType.DESSERT);

    //当天下午四点时间
    // 获取当前日期
    LocalDate currentDate = LocalDate.now();
    // 定义下午 4 点的时间
    LocalTime fourPM = LocalTime.of(17, 0);
    // 结合当前日期和下午 4 点的时间创建 LocalDateTime 实例
    LocalDateTime dateTimeAt4PM = LocalDateTime.of(currentDate, fourPM);

    //汉堡薯条套餐测试
    @Test
    public void myFirstTest() {
        ArrayList<Item> items = new ArrayList<>();
        items.add(hamburger);
        items.add(fries);
        items.add(fries);
        OrderService orderService = new OrderService();
        Order order = orderService.createOrder(items, false, dateTimeAt4PM);
        System.out.println(order);
    }

    //冰咖啡测试
    @Test
    public void mycofe() {
        ArrayList<Item> items = new ArrayList<>();
        items.add(hamburger);
        items.add(fries);
        items.add(icedCoffee);
        OrderService orderService = new OrderService();
        Order order = orderService.createOrder(items, false, dateTimeAt4PM);
        System.out.println(order);
        System.out.println(order.getItems());
    }

    //饮料测试
    @Test
    public void mydrink() {
        ArrayList<Item> items = new ArrayList<>();
        items.add(cola);
        items.add(cola);
        items.add(cola);
        items.add(hamburger);
        OrderService orderService = new OrderService();
        Order order = orderService.createOrder(items, false, dateTimeAt4PM);
        System.out.println(order);
        System.out.println(order.getItems());
    }

    java.io.Console console = System.console();

    //超过五件商品测试
    @Test
    public void mywu() {
        ArrayList<Item> items = new ArrayList<>();
        items.add(cola);
        items.add(cola);
        items.add(cola);
        items.add(hamburger);
        items.add(hamburger);
        items.add(hamburger);
        items.add(hamburger);
        OrderService orderService = new OrderService();
        Order order = orderService.createOrder(items, false, dateTimeAt4PM);
        System.out.println(order);
        System.out.println(order.getItems());
    }
    //为空判断
    @Test
    public void mynull() {
        OrderService orderService = new OrderService();
        Order order = orderService.createOrder(null, false, dateTimeAt4PM);
        System.out.println(order);
        System.out.println(order.getItems());
    }

    //有无主食判断
    @Test
    public void myzhushi() {
        ArrayList<Item> items = new ArrayList<>();
        items.add(cola);
        items.add(cola);
        OrderService orderService = new OrderService();
        Order order = orderService.createOrder(items, false, dateTimeAt4PM);
        System.out.println(order);
        System.out.println(order.getItems());
    }

    //会员判断
    @Test
    public void myhuiyuan() {
        ArrayList<Item> items = new ArrayList<>();
        items.add(cola);
        items.add(hamburger);
        OrderService orderService = new OrderService();
        Order order = orderService.createOrder(items, true, dateTimeAt4PM);
        System.out.println(order);
        System.out.println(order.getItems());
    }

    //自动取消测试cancel+查询订单
    @Test
    public void mycancel() {
        while (true) {

            ArrayList<Item> items = new ArrayList<>();
            items.add(hamburger);
            items.add(fries);
            items.add(fries);
            OrderService orderService = new OrderService();
            Order order = orderService.createOrder(items, false, dateTimeAt4PM);
            System.out.println(order);


            Scanner scanner = new Scanner(System.in);
            int a = scanner.nextInt();
            System.out.println(a);
            HashMap all = orderService.getAll();
            return;

        }

    }

    //修改订单测试
    @Test
    public void updata() {
        //先创建一个订单
        ArrayList<Item> items = new ArrayList<>();
        items.add(hamburger);
        items.add(fries);
        items.add(fries);
        OrderService orderService = new OrderService();
        Order order = orderService.createOrder(items, false, dateTimeAt4PM);
        System.out.println("修改前的订单"+order.getTotalPrice()+"元，包含以下商品"+order.getItems());


        UpdataOrder updataOrder = new UpdataOrder();
        updataOrder.setId(order.getOrderId());
        updataOrder.setStater("部分修改");
        Updatastater updatastater = new Updatastater();
        updatastater.setShuliang(1);//要修改的数量
        updatastater.setStater("删除商品");//要进行的部分修改类型
        hamburger.setStatus(1);//商品是否失效
        updatastater.setItem(hamburger);//要操作的目标商品
        updataOrder.setUpdatastater(updatastater);
        Order updata = orderService.updata(updataOrder, null);
        System.out.println("修改后的订单"+updata.getTotalPrice()+"元，包含以下商品"+updata.getItems());

    }
}
 
